package lib.bone.ext.draft;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author kindear
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_draft")
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
@ApiModel("草稿记录")
public class NepuDraft {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "草稿ID",name = "id")
    String id;

    @Column(name = "user_id")
    @ApiModelProperty("用户ID")
    Long userId;

    @ApiModelProperty("表单标识ID")
    @Column(name = "form_id")
    String formId;

    @ApiModelProperty("表单JSON字符串")
    @Column(name = "form_json_str",length = 2048)
    String formJsonStr;

    @ApiModelProperty(value = "草稿状态",notes = "")
    @Column(name = "status")
    Integer status;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuDraft nepuDraft = (NepuDraft) o;
        return id != null && Objects.equals(id, nepuDraft.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
